package com.xmut.rc.service.impl;

import com.xmut.rc.service.UserRoleService;
import com.xmut.rc.entity.UserRole;
import com.xmut.rc.mapper.UserRoleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @description: 用户角色接口实现
 * @author: XS
 * @date: 2022/5/23
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Resource
    private UserRoleMapper userRoleMapper;

    @Override
    @Transactional
    public boolean updateUserRole(String userId, String roleIds) {
        userRoleMapper.deleteUserRole(userId);
        String[] ids = roleIds.split(",");
        for (String roleId : ids) {
            UserRole userRole=new UserRole();
            userRole.setRoleId(roleId);
            userRole.setUserId(userId);
            userRoleMapper.insert(userRole);
        }
        return true;
    }
}
